import EventManager from "../../../Common/EventManager";
import { EventType } from "../../../GameSpecial/GameEventType";
import gameConfig from "../../config/gameConfig";
import { mgrs, sers } from "../../system/OverallSystem ";
import { GAME_MODE } from "../game/gameMode_Json";
import PageBase from "./pageBase";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ModeSelect extends PageBase {

    public pageName: string = "模式选择";

  
    onLoad() {

    }

    start() {
        // let text = cc.find("layout/text", this.showNode)?.getComponent(cc.Label);
        // if (text) {
        //     text.string = "X " + gameConfig.VIDEO_GET_POWER;
        // }
        // this.node.zIndex = 9999

        if(!window['tiqianjiesuozhuanye']){
            window['tiqianjiesuozhuanye'] = 0
        }
        if(!window['tiqianjiesuozhuanye2']){
            window['tiqianjiesuozhuanye2'] = 0
        }
        if(!window['tiqianjiesuozhuanye3']){
            window['tiqianjiesuozhuanye3'] = 0
        }
        this.gengxincishu()

        let d = sers().userSrv.getDaxiguaData()
        let s = sers().userSrv.getTiyanGame()

        if((d.MaxStarsNumber && d.MaxStarsNumber>=280) || s.indexOf('HechengDaxigua2')>=0){
           this.node.getChildByName('content').getChildByName('panel').getChildByName('lock').children[0].children[0].active = false
        }

        if((d.MaxStarsNumber && d.MaxStarsNumber>=500) || s.indexOf('HechengDaxigua3')>=0){
            this.node.getChildByName('content').getChildByName('panel').getChildByName('heshi').children[0].children[0].active = false
         }

         if((d.MaxStarsNumber && d.MaxStarsNumber>=800) || s.indexOf('HechengDaxigua4')>=0){
            this.node.getChildByName('content').getChildByName('panel').getChildByName('hupai').children[0].children[0].active = false
         }

        this._init();
    }

    protected _init(): void {

        this.open();
    }

    jingdian(){
         if(sers().userSrv.power<=0){
            sers().uiSrv.showUserGetPowerPage();
            return
        }
        sers().userSrv.addPower(-1)
        mgrs().gameMgr.enterMode(GAME_MODE.HechengDaxigua,true);
    }

    jinjie(){

        let d = sers().userSrv.getDaxiguaData()

        let s = sers().userSrv.getTiyanGame()

        // if((!window['tt'] && !window['wx']) || window['GM-mode']){
        // // if(1){
        //     if(sers().userSrv.power<=0){
        //         sers().uiSrv.showUserGetPowerPage();
        //         return
        //     }
        //     sers().userSrv.addPower(-1)
        //     mgrs().gameMgr.enterMode(GAME_MODE.HechengDaxigua2,true);
        //     return
        // }

        if((d.MaxStarsNumber && d.MaxStarsNumber>=280) || s.indexOf('HechengDaxigua2')>=0){
            if(sers().userSrv.power<=0){
                sers().uiSrv.showUserGetPowerPage();
                return
            }
            sers().userSrv.addPower(-1)
            mgrs().gameMgr.enterMode(GAME_MODE.HechengDaxigua2,true);
        }else{
            // sers().uiSrv.showMessage('经典模式达到280星解锁进阶模式')
            sers().platformSrv.platformApi.loadAndShowVideoAd(() => {
                window['tiqianjiesuozhuanye']++
                // this.close();
                this.gengxincishu()
            }, (err) => {
    
            }, null, {
                scene: '提前解锁',
                event: '提前解锁合成进阶模式',
              },'common_video');
        }

    }


    heshi(){
        let d = sers().userSrv.getDaxiguaData()

        let s = sers().userSrv.getTiyanGame()

        // if((!window['tt'] && !window['wx']) || window['GM-mode']){
        // // if(1){
        //     if(sers().userSrv.power<=0){
        //         sers().uiSrv.showUserGetPowerPage();
        //         return
        //     }
        //     sers().userSrv.addPower(-1)
        //     mgrs().gameMgr.enterMode(GAME_MODE.HechengDaxigua2,true);
        //     return
        // }

        if((d.MaxStarsNumber && d.MaxStarsNumber>=500) || s.indexOf('HechengDaxigua3')>=0){
            if(sers().userSrv.power<=0){
                sers().uiSrv.showUserGetPowerPage();
                return
            }
            sers().userSrv.addPower(-1)
            mgrs().gameMgr.enterMode(GAME_MODE.HechengDaxigua3,true);
        }else{
            // sers().uiSrv.showMessage('经典模式达到280星解锁进阶模式')
            sers().platformSrv.platformApi.loadAndShowVideoAd(() => {
                window['tiqianjiesuozhuanye2']++
                // this.close();
                this.gengxincishu()
            }, (err) => {
    
            }, null, {
                scene: '提前解锁',
                event: '提前解锁合十模式',
              },'common_video');
        }

    }

    hupai(){

        // sers().uiSrv.showMessage('暂未开放')
        // return

        let d = sers().userSrv.getDaxiguaData()
        let s = sers().userSrv.getTiyanGame()


        if((d.MaxStarsNumber && d.MaxStarsNumber>=800) || s.indexOf('HechengDaxigua4')>=0){
            if(sers().userSrv.power<=0){
                sers().uiSrv.showUserGetPowerPage();
                return
            }
            sers().userSrv.addPower(-1)
            mgrs().gameMgr.enterMode(GAME_MODE.HechengDaxigua4,true);
        }else{
            // sers().uiSrv.showMessage('经典模式达到280星解锁进阶模式')
            sers().platformSrv.platformApi.loadAndShowVideoAd(() => {
                window['tiqianjiesuozhuanye3']++
                // this.close();
                this.gengxincishu()
            }, (err) => {
    
            }, null, {
                scene: '提前解锁',
                event: '提前解锁胡牌模式',
              },'common_video');
        }

    }

    gengxincishu(){
        let tiqian = this.node.getChildByName('content').getChildByName('panel').getChildByName('lock').children[0].children[0]
        tiqian.getChildByName('tips').getComponent(cc.Label).string = '('+window['tiqianjiesuozhuanye']+'/'+'3)'
        if(window['tiqianjiesuozhuanye'] && window['tiqianjiesuozhuanye']>=3){
            tiqian.active = false
            let s = sers().userSrv.getTiyanGame()
            s.push('HechengDaxigua2')
            sers().userSrv.setTiyanGame(s)
        }

        let tiqian2 = this.node.getChildByName('content').getChildByName('panel').getChildByName('heshi').children[0].children[0]
        tiqian2.getChildByName('tips').getComponent(cc.Label).string = '('+window['tiqianjiesuozhuanye2']+'/'+'3)'
        if(window['tiqianjiesuozhuanye2'] && window['tiqianjiesuozhuanye2']>=3){
            tiqian2.active = false
            let s = sers().userSrv.getTiyanGame()
            s.push('HechengDaxigua3')
            sers().userSrv.setTiyanGame(s)
        }

         let tiqian3 = this.node.getChildByName('content').getChildByName('panel').getChildByName('hupai').children[0].children[0]
        tiqian3.getChildByName('tips').getComponent(cc.Label).string = '('+window['tiqianjiesuozhuanye3']+'/'+'3)'
        if(window['tiqianjiesuozhuanye3'] && window['tiqianjiesuozhuanye3']>=3){
            tiqian3.active = false
            let s = sers().userSrv.getTiyanGame()
            s.push('HechengDaxigua4')
            sers().userSrv.setTiyanGame(s)
        }
    }

}
